package com.chenglai.seckill.service.impl;

import com.chenglai.seckill.dao.GroupOnDetailMapper;
import com.chenglai.seckill.pojo.GroupOnDetail;
import com.chenglai.seckill.service.GroupOnDetailService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：
 *
 * @Author rxh
 * @Date 2023/11/27 11:29
 */
@Service
public class GroupOnDetailServiceImpl implements GroupOnDetailService {

    @Resource
    private GroupOnDetailMapper groupOnDetailMapper;

    @Override
    public List<GroupOnDetail> getGroupOnDetailList(Integer groupId) {
        Example example = new Example(GroupOnDetail.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("groupId",groupId);
        example.orderBy("detailId").desc();
        List<GroupOnDetail> details = groupOnDetailMapper.selectByExample(example);
        return details;
    }

    @Override
    public void editGroupOnDetail(GroupOnDetail groupOnDetail) {
        if (groupOnDetail.getDetailId() == null){
            groupOnDetailMapper.insert(groupOnDetail);
        } else {
            groupOnDetailMapper.updateByPrimaryKeySelective(groupOnDetail);
        }

    }

    @Override
    public void delGroupOnDetail(Integer detailId) {
        groupOnDetailMapper.deleteByPrimaryKey(detailId);
    }

    @Override
    public GroupOnDetail detail(Integer detailId) {
        return groupOnDetailMapper.selectByPrimaryKey(detailId);
    }
}
